<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>WeiCome!微博</h1>
    <div v-if="user.nickname!=null">
        <h2>欢迎回来!{{user.nickname}}主人</h2>
        <a href="/send.html">发微博</a>
        <a href="javascript:void(0)" @click="logout()">退出登录</a>

        <div v-for="item in weiboArr">
            <h3>
                <a :href="'/detail.html?id='+item.id">{{item.nickname}}说:{{item.content}}</a>
                <span>{{item.created}}</span>
            </h3>
            <img :src="item.url" alt="">
        </div>
    </div>
    <div v-else>
        <a href="/login.html">登录</a>
        <a href="/reg.html">注册</a>
    </div>

</div>

<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: 'body>div',
        data: {
            user: "",
            weiboArr: ""
        },
        methods: {
            logout() {
                axios.post("/logout").then(function (response) {
                    v.user = {}

                })
            }
        },
        created: function () {
            axios.get("/currentUser").then(function (response) {
                v.user = response.data
            }),
                axios.get("selectAllWeibo").then(function (response) {
                    v.weiboArr = response.data

                })

        }
    })
</script>
</body>
</html>